function refreshEnd(container){
	if(container.attr('id') == 'plan'){
		var tr = container.find('table>tbody>tr:first');
		tr.trigger('click');
		$('#plan').data('planId',tr.find('a').attr("data-id"));//存储计划id
		listui.refresh('packingList');//刷新箱单列表
	}
}

$(function(){
	$('#plan .list-content-div table thead tr th:last').attr("width","18.5%");
	$('#packingList .list-content-div table thead tr th:last').attr("width","20.5%");
	$('#materielList .list-content-div table thead tr th:last').attr("width","17.5%");
	//点击计划管理列表中相应的行执行
	$('.list-content-div table').removeClass('table-hover');
	//点击计划管理列表中相应的行执行
	//点击计划联动出箱单列表
	$('#plan').delegate('table>tbody>tr','click',function(){
		$(this).closest('tbody').find('tr').each(function(index,obj){
			$(obj).removeClass('row-selected');
		});
		$(this).addClass('row-selected');
		//获取计划id
		var planId = $(event.target||event.srcElement).closest('tr').find('a').attr("data-id");
		$('#plan').data('planId',planId);//存储计划id
		listui.refresh('packingList');//刷新箱单列表
		
	});
	
	$('select.chosen-select').chosen({
	    no_results_text: '没有找到',    // 当检索时没有找到匹配项时显示的提示文本
	    disable_search_threshold: 10, // 10 个以下的选择项则不显示检索框
	    search_contains: true         // 从任意位置开始检索
	});
	
	// 仅选择日期
	$(".form-date").datetimepicker(
	{
	    language:  "zh-CN",
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    format: "yyyy-mm-dd"
	});
	
	//非数字过滤
	$('.number').on('keyup',function(){
		var number=$(this).val();
		number=number.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
		number=number.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的  
		number=number.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
		number=number.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数  
		if(number.indexOf(".")< 0 && number!=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额 
			number= parseFloat(number);
		}
		$(this).val(number);
	});
	
	//三位小数
	$('.bignumber').on('keyup',function(){
		var number=$(this).val();
		number=number.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
		number=number.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的  
		number=number.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
		number=number.replace(/^(\-)*(\d+)\.(\d\d\d).*$/,'$1$2.$3');//只能输入三个小数  
		if(number.indexOf(".")< 0 && number!=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额 
			number= parseFloat(number);
		}
		$(this).val(number);
	});
	
});

//工程路径
var path = $('body').attr('ctxPath');
//保存项目ID.项目名称
//var projectId = $('#projectForm :input[name=id]').val();
$('#projectForm').data('projectId',$('#projectForm :input[name=id]').val());
$('#projectForm').data('projectName',$('#projectForm :input[name=projectName]').val());
//console.log(projectId);



//点击保存项目按钮
$('#updateProject').on('click',function(){
	var params = $('#projectForm').serialize();
	var url = path + '/project/updateProject?_t='+new Date().getTime();
	$.post(url,params,function(data){
		if(data.flag){
			layer.msg(data.msg);
			
			listui.refresh('plan');//刷新计划列表
			listui.refresh('packingList');//刷新箱单列表
		}else{
			layer.msg(data.msg);
			return;
		}
	})
});

//点击新增计划弹出模态框
$('#addPlanBtn').on('click',function(){
	//获取计划编码
	var url = path+'/plan/generatePlanCode?_t='+new Date().getTime();
	$.post(url,function(data){
		if(!data.flag){
			layer.alert(data.msg);
			return;
		}else{
			var url = path +'/plan/getPlanTemplate?_t'+new Date().getTime();
			$('#addPlanModal :input').val('');//清空输入框
			$('#planCode').val(data.msg);//计划编码
			$('#planForm :input[name=projectId]').val($('#projectForm').data('projectId'));//项目Id
			$('#planForm :input[name=projectName]').val($('#projectForm').data('projectName'));//项目名称
			
			
			$('#savePlanBtn').show();
			$('#updatePlanBtn').hide();
			
			$.post(url,function(data){//获取计划模板
				if(!data.flag){//未获取到
					layer.alert(data.msg);
					return;
				}else{
					$('#templateId').empty();
					$(data.planTemplates).each(function(index,obj){
						var option = $('<option/>');
						option.append(option.text(obj.planTemplateName+' ('+obj.planTemplateCode+')'))
						option.append(option.val(obj.id));
						$('#templateId').append('<option selected="selected" disabled="disabled" style="display: none" value="">----请选择一个模板----</option>').append(option);
					});
					$('#addPlanModal').modal({show:true,moveable:true});
				}
			});
		}
	});
});

//当选择不同的模板时触发
$('#templateId').change(function(){
	var templateId = $('#templateId').val();
	var url = path + '/plan/getPlanTemplateByTemplateId/'+ templateId +'?_t='+new Date().getTime();
	$.post(url,function(data){
		$('#startPlace').val(data.planTemplate.startPlaceName);
		$('#endPlace').val(data.planTemplate.destinationName);
		$('#remark').val(data.planTemplate.remarks);
	});
});

//点击保存计划
$('#savePlanBtn').on('click',function(){
	var params = $('#planForm').serialize();
	var url = path+'/plan/addPlan?_t='+new Date().getTime();
	$.post(url,params,function(data){
		if(data.flag){
			$('#addPlanModal').modal("hide");
			layer.alert(data.msg);
			listui.refresh('plan');//刷新计划列表
			listui.refresh('packingList');//刷新箱单列表
		}else{
			layer.msg(data.msg);
			return ;
		}
	});
});



//点击编辑,查看对应计划信息
$('#plan .list-content-div table>tbody').delegate('tr>td>.edit-item', 'click',function() {
	var id = $(this).attr('data-id');
	var url = path + '/plan/edit/'+id+'?_t='+new Date().getTime();
	$.post(url,function(data){
		if(!data.flag){
			layer.alert(data.msg);
			return;
		}else{
			$('#addPlanModal :input').val('');//清空表单
			$('#addPlanModal .modal-title').text("编辑计划");
			$('#planId').val(id);
			$('#planCode').val(data.msg.planCode);
			$('#startDate').val(data.msg.startDate);
			$('#endDate').val(data.msg.endDate);
			$('#weekPolicy').val(data.msg.weekPolicy);
			$('#holidayPolicy').val(data.msg.holidayPolicy);
			$('#updatePlanBtn').show();
			$('#savePlanBtn').hide();
			
			//拼接计划模板
			$('#templateId').empty();
			$(data.planTemplates).each(function(index,obj){
				var option = $('<option/>');
				option.append(option.text(obj.planTemplateName+' ('+obj.planTemplateCode+')'))
				option.append(option.val(obj.id));
				$('#templateId').append(option);
			});
			$('#templateId').val(data.msg.templateId);
			
			$('#startPlace').val(data.msg.startPlaceName);
			$('#endPlace').val(data.msg.destinationName);
			$('#remark').val(data.msg.remark);
			
			
			$('#addPlanModal').modal({'show':true,'moveable':true})
			
		}
	});
	
});

//点击保存按钮 更新计划
$('#updatePlanBtn').on('click',function(){
	var url = path + '/plan/updatePlan?_t='+new Date().getTime();
	var params = $('#planForm').serialize();
	$.post(url,params,function(data){
			if(data.flag){
				$('#addPlanModal').modal('hide');
				layer.alert(data.msg);
				listui.refresh('plan');//刷新计划列表
				listui.refresh('packingList');//刷新箱单列表
			}else{
				layer.msg(data.msg);
				return;
			}
	})
})

//点击删除计划
$('#plan .list-content-div table>tbody').delegate('tr>td>.delete-item', 'click',function() {
	var id = $(this).attr('data-id');
	
	//需要先判断是否含有箱单
	$.post(path+'/plan/searchPackingList/'+id+'?_t='+new Date().getTime(),function(data){
		if(!data.flag){
			layer.alert(data.msg);
			return;
		}else{
			var url = path+"/plan/deletePlan/"+id+"?_t="+new Date().getTime();
			layer.confirm('确定删除该记录吗？',{btn:['确定','取消']},function(){
				$.post(url,function(data){
					if(data.flag){
						layer.msg(data.msg);
						listui.refresh('plan');//刷新计划列表
						listui.refresh('packingList');//刷新箱单列表
					}else{
						layer.msg(data.msg);
						return;
					}
				})
			});
			}
		});
});

//箱单物料导入
$('#plan .list-content-div table>tbody').delegate('tr>td>.import', 'click',function() {
	var id = $(this).attr('data-id'); //计划ID
	$('#xiangdanImport').modal({'moveable':true,'show':true});
	//模板下载
	$('#templateDownload').on("click",function(){
		location.href=path+"/packingList/download?fileName=箱单物料模板.xls";
	});
	//导入
	$('#uploaderExample').uploader({
	    autoUpload: true,            // 当选择文件后立即自动进行上传操作
	    url: path+'/packingList/importExcel/'+ id +'?_t='+new Date().getTime(),  // 文件上传提交地址
	    filters:{
	        // 只允许上传excel文件
	        mime_types: [ {title: 'Excel文档', extensions: 'xls'}],
	        // 最大上传文件为 1MB
	        max_file_size: '1mb',
	        //允许上传重复文件
	        prevent_duplicates: false 
	    },
	    responseHandler:function (responseObject, file) {
			  if (responseObject.status == 200) {
				  //console.log(responseObject);
				  if(JSON.parse(responseObject.response).flag){//导入成功
					  $('#xiangdanImport .file').empty();
					  $('#xiangdanImport').modal('hide');
				    	layer.alert(JSON.parse(responseObject.response).msg);
				    	listui.refresh('packingList');//刷新箱单列表
				  }else{//导入失败
					  layer.alert(JSON.parse(responseObject.response).msg);
					  $('#xiangdanImport .file').empty();
				  }
			 };
		 }
		}
	);
});


//点击添加箱单按钮
$('#addPackingListBtn').on('click',function(){
	$('#packingListCode').val('');//给编码设置值
	//获取箱单编码
	var url = path + '/packingList/generateCode?_t='+new Date().getTime();
	$.post(url,function(data){
		if(data.flag==false){//未获取到箱单编码
			layer.alert(data.msg);
			return;
		}else{
			if($('#plan').data('planId')==null){
				layer.alert('请先指定一个计划再进行添加');
				return;
			}else{
				$('#addPackingListModal :input').val('');//清空表单
				$('#packingListCode').val(data.msg);//给编码设置值
				$('#packingListForm input[name=planId]').val($('#plan').data('planId'));//设置隐藏域planId的值
				$(".modal-footer #updatePackingListBtn").hide();//隐藏更新按钮
				$(".modal-footer #savePackingListBtn").show();//显示保存按钮
				$('#addPackingListModal').modal({'show':true,'moveable':true});
			}
			
		}
	});
	
})

//点击箱单保存按钮
$('#savePackingListBtn').on('click',function(){
	var params = $('#packingListForm').serialize();
	var	 url = path + "/packingList/addPackingList?_t="+new Date().getTime();
	$.post(url,params,function(data){
		if(data.flag){
			$('#addPackingListModal').modal('hide');
			layer.alert(data.msg);
			listui.refresh('packingList');//刷新箱单列表
		}else{
			layer.msg(data.msg)
			return;
		}
	});
});

//点击编辑按钮
$('#packingList .list-content-div table>tbody').delegate('tr>td>.edit-item', 'click',function() {
	
	$('#addPackingListModal :input').val('');//清空表单
	$('#addPackingListModal .modal-title').text('编辑箱单');
	var id = $(this).attr('data-id');//根据id查询箱单表获取记录
	var planId = $(this).attr('plan-id');//拿到所属计划id.
	var url = path + '/packingList/lookPackingList/'+id+"?_t="+new Date().getTime();
	$.post(url,function(data){
		
		$('#packingListCode').val(data.packingListCode);
		$('#owner').val(data.owner);
		$('#shipper').val(data.shipper);
		$('#receiver').val(data.receiver);
		$('#emptyWeight').val(data.emptyWeight);
		$('#grossWeight').val(data.grossWeight);
		$('#volume').val(data.volume);
		$('#takePhoto').val(data.takePhoto);
		
		$('#packingListForm input[name=id]').val(id);//给隐藏域赋值.箱单ID
		$('#packingListForm input[name=planId]').val(planId);//计划ID
		
		$(".modal-footer #updatePackingListBtn").show();//显示更新按钮
		$(".modal-footer #savePackingListBtn").hide();//隐藏保存按钮
		$('#addPackingListModal').modal({'show':true,'moveable':true});
	});
	
});

//点击保存按钮 更新箱单
$('#updatePackingListBtn').on('click',function(){
	var url =path + '/packingList/updatePackinglist?_t='+new Date().getTime();
	var params = $('#packingListForm').serialize();
	$.post(url,params,function(data){
		if(data.flag){
			$('#addPackingListModal').modal('hide');
			layer.alert(data.msg);
			listui.refresh('packingList');//刷新箱单列表
		}else{
			layer.msg(data.msg);
			return;
		}
	});
});

//点击删除对应箱单记录
$('#packingList .list-content-div table>tbody').delegate('tr>td>.delete-item', 'click',function() {
	var id = $(this).attr('data-id');
	//需要先判断箱单中是否有物料
	$.post(path+'/packingList/searchMateriel/'+id+'?_t='+new Date().getTime(),function(data){
		if(!data.flag){
			layer.alert(data.msg);
			return;
		}else{
			var url = path + '/packingList/deletePackingList/'+id+'?_t='+new Date().getTime();
			layer.confirm(data.msg+'确定删除该记录吗？',{btn:['确定','取消']},function(){
				$.post(url,function(data){
					if(data.flag){
						layer.msg(data.msg);
						listui.refresh('packingList');//刷新箱单列表
					}else{
						layer.msg(data.msg);
						return ;
					}
				})
			});
			}
		});
});

//控制二维码与数量
function amountChange(){
	if($("#materielAmount").val()==0){
		$("#materielAmount").val("1");
	}else if($("#materielAmount").val()!=1){
		$("#materielQrcode").val("");
		$("#materielQrcode").attr("disabled","disabled");
	}else{
		$("#materielQrcode").removeAttr("disabled");
	}
}

//点击物料管理
$('#packingList .list-content-div table>tbody').delegate('tr>td>.look-item', 'click',function() {
	
	//获取箱单ID和编码.公司ID.存入materielModal
	$('#materielModal').data('packingListId',$(this).attr('data-id'));
	$('#materielModal').data('packingListCode',$(this).attr('packingListCode'));
	$('#materielModal').data('companyId',$(this).attr('companyId'));
	
	listui.refresh('materielList');//刷新物料展示窗口
	$('#materielModal').modal({'show':true,'moveable':true});
	
})

//点击添加物料信息
$('#addPackingListMaterielBtn').on('click',function(){
	$('#addMaterielModal :input').val('');
	//给f4query设置urlParams 参数.
	$("[table='getMaterielCodeByCompanyId']").attr("urlParams",'{"companyId":"'+$('#materielModal').data('companyId')+'"}');
	
	$('#addMaterielModal').modal({'show':true,'moveable':true});
});

//点击物料保存
$('#savePackingListMateriel').on('click',function(){
	//加载层
	layer.load(2);
	$("#packingListMaterielForm input[name=packingListId]").val($('#materielModal').data('packingListId'));
	$("#packingListMaterielForm input[name=packingListCode]").val($('#materielModal').data('packingListCode'));
	var params = $('#packingListMaterielForm').serialize();
	var url = path + '/packingListMateriel/savePackingListMateriel?_t='+new Date().getTime();
	$.post(url,params,function(data){
		if(data.flag){
			//此处加载层关闭
			layer.closeAll('loading');
			$('#addMaterielModal').modal('hide');
			layer.alert(data.msg);
			listui.refresh('materielList');
		}else{
			layer.closeAll('loading');
			layer.msg(data.msg);
			return;
		}
	});
});
//点击物料信息中的删除
$('#materielList .list-content-div table>tbody').delegate('tr>td>.delete-item', 'click',function() {
	
	var id = $(this).attr('data-id');
	var url = path + '/packingListMateriel/deletePackingListMateriel/'+id+'?_t='+new Date().getTime();
	layer.confirm('确定删除该记录吗？',{btn:['确定','取消']},function(){
		$.post(url,function(data){
			if(data.flag){
				layer.msg(data.msg);
				listui.refresh('materielList');
			}else{
				layer.msg(data.msg);
			}
		})
	});
});


//点击物料PDF导出
$('#packingList .list-content-div table>tbody').delegate('tr>td>.export', 'click',function() {
	layer.load(2);
	//确定导出信息
	var id = $(this).attr('data-id');//拿到箱单ID.
	var url = path + '/packingListMateriel/exportPDF/'+id+'?_t='+new Date().getTime();
	$.post(url,function(data){
		if(data.flag){
			location.href = path+"/packingListMateriel/download?fileName=materiel.pdf";
			layer.closeAll('loading');
		}
	})
	
});

//点击二维码查看物料大图
$('#materielList .list-content-div table>tbody').delegate('tr>td>.qrcode','click',function(){
	$('#code').empty();//清空二维码的内容
	var qrcode=$(this).attr('qrcode');
	if(qrcode!=null&&qrcode!=""){
		var qrcodeInfo=qrcode;
	}else{
		var packingListMaterielId = $(this).attr('packingListMaterielId');
		var qrcodeInfo ='1;' + packingListMaterielId;
	}
	 $('#code').qrcode(toUtf8(qrcodeInfo));//如果无默认则 二维码内容是1;+箱单物料关系表ID
	
	$("#qrcodeModal").modal({'show':true,'moveable':true});
});

//点击查看打尺记录
$('#materielList .list-content-div table>tbody').delegate('tr>td>.rule-record', 'click',function() {
	var id = $(this).attr('data-id');
	var url = path + '/ruleRecord/getRuleRecord';
	//获取打尺记录.
	$.ajax({
		url:url,
		data:{'id':id},
		type:'POST',
		dataType:'JSON',
		success:function(data){
			if(!data.flag){
				layer.alert(data.msg);
				return;
			}else{
				$('#ruleRecord').empty();
				var obj = data.msg;
				var html =[];
				for(var i =0 ; i<obj.length;i++){
					var photosHtml="";
					var photos=obj[i].picList;
					if(photos.length==0){
						photosHtml="<img class='pic' src='/bartalks/not-photo.png'  id='"+obj[i].id+"'  style='width:20px;height:20px;' title='点击查看大图' alt='图片不见了....'/>&nbsp;&nbsp;&nbsp;";
					}else{
						for(var x =0 ;x<photos.length;x++){
							photosHtml+="<img class='pic' src='"+photos[x]+"'  id='"+obj[i].id+"'  style='width:20px;height:20px;' title='点击查看大图' alt='图片不见了....'/>&nbsp;&nbsp;&nbsp;";
						}
					}
					html.push("<tr><td>"+obj[i].positionName+"</td><td>"+obj[i].ruleDate+"</td><td>"+obj[i].weight+"</td><td>"+obj[i].length+"</td><td>"+obj[i].width+"</td><td>"+obj[i].height+"</td><td>"+obj[i].description+"</td><td>"+photosHtml+"</td></tr>");
				}
				$('#ruleRecord').append(html);
			}
			$('#ruleRecordModal').modal({'show':true,'moveable':true});
			//点击查看打尺照片
			$('#ruleRecordModal  table>tbody').on('click','tr>td>img',function(){
				var picSrc=	$(this).attr("src");
				$('#recordPic').attr('src',picSrc);
				$('#recordPicModal').modal({'show':true,'moveable':true});
			});
		},
		error:function(data){
			layer.alert("网络异常");
		}
	});
});


//点击查看强制拍照记录/业务记录
$('#materielList .list-content-div table>tbody').delegate('tr>td>.forced-photo', 'click',function() {
	var id = $(this).attr('data-id');
	var url = path + '/forcedPhoto/list';
	//获取业务记录.
	$.ajax({
		url:url,
		data:{'id':id},
		type:'POST',
		dataType:'JSON',
		success:function(data){
			if(!data.flag){
				layer.alert(data.msg);
				return;
			}else{
				$('#planBiz').empty();
				var obj = data.msg;
				var html =[];
				for(var i =0 ; i<obj.length;i++){
					var photosHtml="";
					var photos=obj[i].picList;
					if(photos==null){
						photosHtml="<img class='pic' src='/bartalks/not-photo.png'  id='"+obj[i].id+"'  style='width:20px;height:20px;' title='点击查看大图' alt='图片不见了....'/>&nbsp;&nbsp;&nbsp;";
				    }else{
					for(var x =0 ;x<photos.length;x++){
						photosHtml+="<img class='pic' src='"+photos[x]+"'  id='"+obj[i].id+"'  style='width:20px;height:20px;' title='点击查看大图' alt='图片不见了....'/>&nbsp;&nbsp;&nbsp;";
				 	 }
				    }
					html.push("<tr><td>"+obj[i].positionName+"</td><td>"+obj[i].containerName+"</td><td>"+obj[i].bizType+"</td><td>"+obj[i].bizDate+"</td><td>"+obj[i].userName+"</td><td>"+photosHtml+"</td></tr>");
				}
				$('#planBiz').append(html);
			}
			$('#planbizModal').modal({'show':true,'moveable':true});
			//点击查看打尺照片
			$('#planbizModal  table>tbody').on('click','tr>td>img',function(){
				var picSrc=	$(this).attr("src");
				$('#forcedPhoto').attr('src',picSrc);
				$('#forcedPhotoModal').modal({'show':true,'moveable':true});
			});
		},
		error:function(data){
			layer.alert("网络异常");
		}
	});
});



//自定义查询条件
function getCustomQueryData(container) {
	if(container.attr('id')=='plan'){
		//根据项目Id查询计划
		var projectId = $('#projectForm').data('projectId');
		if (projectId == "") {
			return ;
		}
		return {
			'projectId' : projectId
		}
	}
	if(container.attr('id')=='packingList'){
		//根据计划Id查询箱单
		var planId = $('#plan').data('planId');
		if (planId == "") {
			return ;
		}
		return {
			'planId' : planId
		}
	}
	if(container.attr('id')=='materielList'){
		//根据箱单Id查询物料
		var packingListId = $('#materielModal').data('packingListId');
		if (packingListId == "") {
			return ;
		}
		return {
			'packingListId' : packingListId
		}
	}
}


//自定义表格信息
function handleCellValue(tfNotUnderline, cellVal, obj, container) {// (列名，单元格值，行对象)
	if(container.attr('id')=='plan'){
		if (tfNotUnderline == "startDate" || tfNotUnderline == "endDate" ) {
			var rgExp = '00:00:00';
			if (cellVal.match(rgExp)) {
				return cellVal.replace(rgExp, '');
			}
		} else if(tfNotUnderline=="started") {
			if (cellVal == 0) {
				return '已启动';
			} else {
				return '未启动';
			}
		}else{
			return cellVal;
		}
	}else if(container.attr('id')=='packingList'){
		if(tfNotUnderline=='takePhoto'){
			if(cellVal=='0'){
				return'是';
			}else{
				return '否';
			}
		}
		return cellVal;
	}else if(container.attr('id')=='materielList'){
		if(tfNotUnderline=='takePhoto'){
			if(cellVal=='0'){
				return'是';
			}else{
				return '否';
			}
		}else if(tfNotUnderline=='materielQrcode'){
				return '<img class="qrcode" src="'+path+'/eg.png" alt="二维码" style="width :20px"  title="点击查看大图" packingListMaterielId="'+obj.id+'" qrcode="'+obj.materielQrcode+'" >';
		}
		return cellVal;
	}
}

//自定义表格操作按钮
function handleOpRow(tr, obj,container) {
	if(container.attr('id')=='plan'){
		if(obj.started==1){
			tr.append($('<td/>').addClass('op').append($('<a/>', {
				"href" : "javascript:;",
				"data-id" : obj.id
			}).addClass('started').text('启动')).append($('<span/>').text('  |  ')).append($('<a/>', {
				"href" : "javascript:;",
				"data-id" : obj.id
			}).addClass('edit-item').text('编辑')).append($('<span/>').text('  |  ')).append($('<a/>', {
				"href" : "javascript:;",
				"data-id" : obj.id
			}).addClass('delete-item').text('删除')).append($('<span/>').text('  |  ')).append($('<a/>', {
				"href" : "javascript:;",
				"data-id" : obj.id
			}).addClass('import').text('箱单物料导入')));
		}else if(obj.started==0){
			tr.append($('<td/>').addClass('op').append($('<a/>', {
				"href" : "javascript:;",
				"data-id" : obj.id
			}).addClass('started').text('暂停')).append($('<span/>').text('  |  ')).append($('<a/>', {
				"href" : "javascript:;",
				"data-id" : obj.id
			}).addClass('edit-item').text('编辑')).append($('<span/>').text('  |  ')).append($('<a/>', {
				"href" : "javascript:;",
				"data-id" : obj.id
			}).addClass('delete-item').text('删除')).append($('<span/>').text('  |  ')).append($('<a/>', {
				"href" : "javascript:;",
				"data-id" : obj.id
			}).addClass('import').text('箱单物料导入')));
		}
	}else if(container.attr('id')=='packingList'){
		tr.append($('<td/>').addClass('op').append($('<a/>', {
			"href" : "javascript:;",
			"data-id" : obj.id,
			"plan-id":obj.planId
		}).addClass('edit-item').text('编辑')).append($('<span/>').text('  |  ')).append($('<a/>', {
			"href" : "javascript:;",
			"data-id" : obj.id
		}).addClass('delete-item').text('删除')).append($('<span/>').text('  |  ')).append($('<a/>', {
			"href" : "javascript:;",
			"data-id" : obj.id,
			"packingListCode":obj.packingListCode,
			"companyId":obj.companyId
		}).addClass('look-item').text('物料管理')).append($('<span/>').text('  |  ')).append($('<a/>', {
			"href" : "javascript:;",
			"data-id" : obj.id
		}).addClass('export').text('物料PDF导出')));
	}else if(container.attr('id')=='materielList'){
		tr.append($('<td/>').addClass('op').append($('<a/>', {
			"href" : "javascript:;",
			"data-id" : obj.id,
			"materielCode":obj.materielCode
		}).addClass('rule-record').text('打尺记录')).append($('<span/>').text('  |  ')).append($('<a/>', {
			"href" : "javascript:;",
			"data-id" : obj.id
		}).addClass('forced-photo').text('业务记录')).append($('<span/>').text('  |  ')).append($('<a/>', {
			"href" : "javascript:;",
			"data-id" : obj.id
		}).addClass('delete-item').text('删除')));
	}
}

//解决qrcode中文乱码
function toUtf8(str) {
    var out, i, len, c;
    out = "";
    len = str.length;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if ((c >= 0x0001) && (c <= 0x007F)) {
            out += str.charAt(i);
        } else if (c > 0x07FF) {
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
            out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        } else {
            out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        }
    }
    return out;
}

//启动,暂停
$('.list-content-div table>tbody').delegate('tr>td>.started', 'click', function() {
	var id = $(this).attr('data-id');
	var container = $(this).closest('.listui');
	var val = container.context.innerText;
	var started =  val == "启动" ? 0 : 1;
	//发请求更改状态.
	$.post(path+'/plan/start?_t+'+new Date().getTime(),{"id":id,"started":started},function(data){
		if(data.flag){
			layer.msg(data.msg);
			listui.refresh('plan');
		}else{
			layer.msg(data.msg);
		}
	})
});

$("#excle").click(function(){
	var packingListId = $('#materielModal').data('packingListId');
	if (packingListId == "") {
		layer.alert("数据错误,无箱单数据!");
		return ;
	}else{
		//下载Excel
		location.href= path+'/packingListMateriel/export/'+packingListId;
	}
	
})
